package com.example.administrator.order_broadcast;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btn1;
    private HighPriorityReceiver highPriorityReceiver;
    private MiddlePriorityReceiver middlePriorityReceiver;
    private LowPriorityReceiver lowPriorityReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*静态注册*/
//        highPriorityReceiver=new HighPriorityReceiver();
//        IntentFilter highFilter=new IntentFilter();
//        highFilter.addAction("Order_Broadcast");
//        highFilter.setPriority(100);
//        registerReceiver(highPriorityReceiver,highFilter);
//
//        middlePriorityReceiver=new MiddlePriorityReceiver();
//        IntentFilter middleFilter=new IntentFilter();
//        middleFilter.addAction("Order_Broadcast");
//        middleFilter.setPriority(50);
//        registerReceiver(middlePriorityReceiver,middleFilter);
//
//        lowPriorityReceiver=new LowPriorityReceiver();
//        IntentFilter lowFilter=new IntentFilter();
//        lowFilter.addAction("Order_Broadcast");
//        lowFilter.setPriority(0);
//        registerReceiver(lowPriorityReceiver,lowFilter);
        findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setAction("Order_Broadcast");
                sendOrderedBroadcast(intent,null);//null表示指定的权限，设置为低中高三个

            }
        });
    }
            }
